package com.xyl.springboot.msg.send;

import cn.hutool.core.date.DateUtil;
import com.xyl.springboot.cfg.Constant;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * CompletableFuture<SendResult<K, V>> send(String topic, V data);
 * CompletableFuture<SendResult<K, V>> send(String topic, K key, V data);
 * CompletableFuture<SendResult<K, V>> send(String topic, Integer partition, K key, V data);
 * CompletableFuture<SendResult<K, V>> send(String topic, Integer partition, Long timestamp, K key, V data);
 * CompletableFuture<SendResult<K, V>> send(ProducerRecord<K, V> record);
 * CompletableFuture<SendResult<K, V>> send(Message<?> message);
 */
@Slf4j
@Component
public class SendingMessage {

    @Resource
    private KafkaTemplate kafkaTemplate;

    @Scheduled(fixedRate = 3000)
    public void fixedRateTask() {
        String now = DateUtil.now();
        System.out.println("Fixed rate task - " + now);
        kafkaTemplate.send(Constant.DB,now);
    }


}